package com.woniuxy.business.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.business.service.MessageService;
import com.woniuxy.commons.entity.Message;
import com.woniuxy.commons.entity.QueryEntity;
import com.woniuxy.commons.service.MedicineService;
import com.woniuxy.commons.utils.ResponseResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 雷珉
 * @date 2022年06月08日 16:41
 */
@RestController
@RequestMapping("/business/message")
public class MessageController {
    @Resource
    private MessageService messageService;

    @GetMapping("/")
    public ResponseResult<List<Message>> findAll(){
        return messageService.findAll();
    }

    @PostMapping("/condition")
    public ResponseResult<PageInfo<Message>> findAllByCondition(@RequestBody QueryEntity<Message> queryEntity){
        return messageService.findAllByCondition(queryEntity);
    }

    @GetMapping("/{id}")
    public ResponseResult<Message> findOne(@PathVariable("id") int id){
        return messageService.findOne(id);
    }

    @PostMapping("/")
    public ResponseResult addOne(@RequestBody Message Message){
        return messageService.addOne(Message);
    }

    @PutMapping("/")
    public ResponseResult updateOne(@RequestBody Message Message){
        return messageService.updateOne(Message);
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteOne(@PathVariable("id") int id){
        return messageService.deleteOne(id);
    }

    @PostMapping("/batchDel")
    public ResponseResult deleteBatch(@RequestBody int[] ids){
        return messageService.deleteBatch(ids);
    }

    @PostMapping("/send/{messageId}")
    public ResponseResult send(@PathVariable("messageId") int messageId,@RequestBody int[] userIds){
        return messageService.send(messageId,userIds);
    }
}

